<?php

use Doraemon\tools\Log;
use Doraemon\service\Milvus\BusinessJudgeArticle;

class SignupAction extends ActionPlugin
{
    const IS_TRACING = true;

    /**
     * 商业用户入住案例图片查重
     */
    public function main()
    {
        Log::info('messageBody', $this->messageBody);

        if (!$this->messageBody['database']) throw new \Exception('未获取到数据库');
        if (!$this->messageBody['table']) throw new \Exception('未获取到数据表');
        if (!$this->messageBody['data']) throw new \Exception('未接收到数据');

        $data = $this->messageBody['data'];
        $pic_list = json_decode($data['pic_list'], true);
        foreach($pic_list as $key => $article) {
            $aid = "{$data['id']}_$key";
            $addTime = $data['edit_time'] ?: $data['add_time'];
            BusinessJudgeArticle::saveArticle($aid, $article['list'], $addTime, $data['uid'], 1);
        }

        $this->setSuccess();
    }
}
